% TEST_ID: LANG-EXPAND-0022
% CATEGORY: language/array-ops/cat
% 测试 double 数组之间的拼接行为

function test_double_cat
    A = ones(3);
    B = zeros(3);
    C1 = cat(1, A, B);
    r = [1 1 1
        1 1 1
        1 1 1
        0 0 0
        0 0 0
        0 0 0];

    assert_isequal(C1, r);
    C2 = cat(2, A, B);
    r = [1 1 1 0 0 0
        1 1 1 0 0 0
        1 1 1 0 0 0];
    assert_isequal(C2, r);

    C = reshape(1:9, 3, 3);
    r = cat(1, A, B, C);
    result = [1 1 1
        1 1 1
        1 1 1
        0 0 0
        0 0 0
        0 0 0
        1 4 7
        2 5 8
        3 6 9];
    assert_isequal(r, result);

    M1 = [1 2; 3 4];
    M2 = [5 6; 7 8];
    A1 = {M1, M2};
    Cvert = cat(1, A1{:});
    result = [1 2
        3 4
        5 6
        7 8];
    assert_isequal(Cvert, result);

    Chorz = cat(2, A1{:});
    result = [1 2 5 6
        3 4 7 8];
    assert_isequal(Chorz, result);


    a = cat(1, [65 66 67], ['c' 'd' 'd']);
    result = ['ABC'
        'cdd'];
    assert_isequal(a, result);

    clear A B

    A(:, :, 1) = [
        3 10
        6 10
    ];

    A(:, :, 2) = [
        2 10
        10 5
    ];

    B(:, :, 1) = [
        9 5
        2 10
    ];


    B(:, :, 2) = [
        8 7
        10 1
    ];

    ABA2(:, :, 1) = [
        3 10 9 5 3 10
        6 10 2 10 6 10
    ];

    ABA2(:, :, 2) = [
        2 10 8 7 2 10
        10 5 10 1 10 5
    ];

    assert(cat(2, A, B, A) == ABA2);


    ABA3(:, :, 1) = [
        3 10
        6 10
    ];

    ABA3(:, :, 2) = [
        2 10
        10 5
    ];

    ABA3(:, :, 3) = [
        9 5
        2 10
    ];

    ABA3(:, :, 4) = [
        8 7
        10 1
    ];

    ABA3(:, :, 5) = [
        3 10
        6 10
    ];

    ABA3(:, :, 6) = [
        2 10
        10 5
    ];

    assert(cat(3, A, B, A) == ABA3);

    A = eye(3);
    Y = cat(4, A, 2 * A, 3 * A, 4 * A);
    result = zeros(3, 3, 1, 4);
    result(:, :, 1, 1) = [1 0 0
                        0 1 0
                        0 0 1];


    result(:, :, 1, 2) = [2 0 0
                        0 2 0
                        0 0 2];


    result(:, :, 1, 3) = [3 0 0
                        0 3 0
                        0 0 3];


    result(:, :, 1, 4) = [4 0 0
                        0 4 0
                        0 0 4];

    assert_isequal(Y, result);

end


function assert_isequal(x, y)
    assert(isequal(x, y));
end